define(['jquery', '/libs/cookie/jquery.cookie.js'], () => {
    // require(['/libs/cookie/jquery.cookie.js'], () => {
    class header {
        constructor() {
            this.loadHTML().then(() => {
                this.countNum()
                this.reload()
                this.unLogin()
            })
        }
        loadHTML() {
            return new Promise(resolve => {
                $('.header').load('/html/modules/header.html', resolve)
            })
        }
        countNum() {
            let count = 0;
            let cart = localStorage.getItem('cart')
            if (cart) {
                cart = JSON.parse(cart)
                var price = cart.reduce((total, shop) => {
                    total += shop.price * shop.count
                    count += shop.count
                    return total
                }, 0)
            }
            if (price)
                $('#priceNum').html("￥" + (price.toFixed(2)))
            $('#cartNum').html(count + "件")
        }
        reload() {
            // console.log($.cookie('name'))
            // $('.header-top-other:first-child').addClass('ac').next().removeClass('ac')
            if ($.cookie('name')) {
                $('.myLove').html($.cookie('name'))
                $('.ac').show().prev().hide()
            }

        }
        unLogin() {
            $('.unLogin').on('click', () => {
                $.removeCookie('name', { path: '/' })
                $('.ac').hide().prev().show()
            })
        }
        login() {
            $('.loginL').on('click', () => {
                this.reload()
            })
        }
    }
    return new header()
        // })
        // return 'pd'
})